﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

public class FM_TimeSignature : FM_BaseNote
{
    public FM_TimeSignatureValue timeSigN;
    public FM_TimeSignatureValue timeSigD;

    public FM_TimeSignature(FM_TimeSignatureValue timeSigN, FM_TimeSignatureValue timeSigD, FM_ScoreBase score)
        : base(FM_NoteType.KEY_SIGNATURE, score)
    {
        this.timeSigN = timeSigN;
        this.timeSigD = timeSigD;
    }

    public override float GetDisplacement()
    {
        return 0.0f;
    }

    public override string AsString()
    {
        return FM_Const._4;
    }

    public override float WidthAccidental()
    {
        return 0;
    }

    public override float WidthNoteNoStem()
    {
        if (score.score == null) return 0;
        string s = AsString();
        if (s.Equals("")) return 0;
        FM_Const.AdjustFont(score.score, AsString(), 2);
        return score.score.Font.MeasureText(AsString());
    }

    public override float WidthNote()
    {
        return WidthNoDotNoStem();
    }

    public override float WidthDot()
    {
        return 0;
    }

    public override void DrawNote(ScoreCanvas canvas)
    {
        if (score.score == null) return;
        if (!IsVisible()) return;
        base.DrawNote(canvas);

        score.score.Font.Color = color;
        float dx = StartX + GetPaddingLeft();
        float y = StartY1;
        FM_Const.AdjustFont(score.score, FM_Const._4, 2);

        DrawTimeSignature(canvas, timeSigN, dx, y + 1 * score.score.GetDistanceBetweenStaveLines());
        DrawTimeSignature(canvas, timeSigD, dx, y + 3 * score.score.GetDistanceBetweenStaveLines());
    }

    private void DrawTimeSignature(ScoreCanvas canvas, FM_TimeSignatureValue timeSigValue, float dx, float y)
    {
        switch (timeSigValue)
        {
            case FM_TimeSignatureValue._2:
                canvas.DrawText(FM_Const._2, dx, y, score.score.Font);
                break;
            case FM_TimeSignatureValue._3:
                canvas.DrawText(FM_Const._3, dx, y, score.score.Font);
                break;
            case FM_TimeSignatureValue._4:
                canvas.DrawText(FM_Const._4, dx, y, score.score.Font);
                break;
            case FM_TimeSignatureValue._5:
                canvas.DrawText(FM_Const._5, dx, y, score.score.Font);
                break;
            case FM_TimeSignatureValue._6:
                canvas.DrawText(FM_Const._6, dx, y, score.score.Font);
                break;
            case FM_TimeSignatureValue._7:
                canvas.DrawText(FM_Const._7, dx, y, score.score.Font);
                break;
            case FM_TimeSignatureValue._8:
                canvas.DrawText(FM_Const._8, dx, y, score.score.Font);
                break;
            case FM_TimeSignatureValue._9:
                canvas.DrawText(FM_Const._9, dx, y, score.score.Font);
                break;
        }
    }

    public override float Left()
    {
        return StartX + paddingLeft;
    }

    public override float Bottom()
    {
        return StartY1 + 4 * score.score.GetDistanceBetweenStaveLines();
    }

    public override float Right()
    {
        return StartX + Width();
    }

    public override float Top()
    {
        return StartY1;
    }

    private float Height()
    {
        return 4 * score.score.GetDistanceBetweenStaveLines();
    }
}